#ifndef USVGICONENGINE_H
#define USVGICONENGINE_H

#include<QIconEngine>
#include<QWidget>
#include<QSharedData>
#include<QString>
#include<QSharedDataPointer>



struct SvgIconEntry //标识一张svg图片对象
{
    QSize size;
    QIcon::Mode mode;
    QIcon::State state;
};

class USvgIconEnginePrivate;

class USvgIconEngine : public QIconEngine
{
private:
//    QSharedDataPointer<USvgIconEnginePrivate> d_ptr;
    USvgIconEnginePrivate* d_ptr;

public:
    USvgIconEngine();
    USvgIconEngine(const USvgIconEngine& other);//拷贝构造
    ~USvgIconEngine();
public:
    void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state) override;
    void addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state) override;

    void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
    QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
    QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) override;

    QString key() const override;
    QIconEngine *clone() const override;

    bool read(QDataStream &in) override;
    bool write(QDataStream &out) const override;

    void virtual_hook(int id, void *data) override;
public:
    //辅助函数
    const QString getBaseSvg() const;
    void printPixmapCache(const QHash<int, QPixmap>* pixmapCache);
    void printSvgCache(const QHash<int, QString>* svgCache);
    const QHash<int,QString>* getSvgCache() const;

    void printPcmCache();
};

#endif
